package com.bawei.doctor.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bawei.doctor.vo.DoctorListVo;
import com.bawei.doctor.vo.DoctorVo;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bawei.common.utils.PageUtils;
import com.bawei.common.utils.Query;

import com.bawei.doctor.dao.HospitalDoctorDao;
import com.bawei.doctor.entity.HospitalDoctorEntity;
import com.bawei.doctor.service.HospitalDoctorService;
import org.springframework.web.bind.annotation.PostMapping;


@Service("hospitalDoctorService")
public class HospitalDoctorServiceImpl extends ServiceImpl<HospitalDoctorDao, HospitalDoctorEntity> implements HospitalDoctorService {

    @SuppressWarnings("all")
    @Autowired
    HospitalDoctorDao hospitalDoctorDao;
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        QueryWrapper<HospitalDoctorEntity> w = new QueryWrapper<>();

        //只展示审批状态为1 已通过 的医生信息
        w.eq("doctor_approval_state",1);

        //医生名或者手机号
        if (key!=null &&!"".equals(key)){
            w.like("doctor_name",key).or().like("phone",key);
        }

        IPage<HospitalDoctorEntity> page = this.page(
                new Query<HospitalDoctorEntity>().getPage(params),
                w
        );

        return new PageUtils(page);
    }



    //查询某医院的统计信息
    @Override
    public PageUtils enterHospital(String typeName, int parentId,int page, int size) {

        Page<DoctorVo> doctorVoPage = new Page<>(page, size);
       IPage<DoctorVo> doctorVoIPage= hospitalDoctorDao.enterHospital(doctorVoPage,typeName,parentId);
        PageUtils pageUtils = new PageUtils(doctorVoIPage);
        return pageUtils;
    }

    //查询该等级下的医生统计信息
    @Override
    public PageUtils administrativeList(Map<String, Object> params) {

        //获取分页
        String atPage = (String) params.get("page");
        Integer page = Integer.valueOf(atPage);
        String atLimit = (String) params.get("limit");
        Integer limit = Integer.valueOf(atLimit);
      //获取该等级的ID
        String administrativeId = (String) params.get("administrativeId");
        Integer adminId = Integer.valueOf(administrativeId);

        Page<DoctorListVo> doctorListVoPage = new Page<>(page, limit);
        IPage<DoctorListVo> all=hospitalDoctorDao.administrativeList(doctorListVoPage,adminId);
        PageUtils pageUtils = new PageUtils(all);
        return pageUtils;
    }

    //该医院的科室统计信息
    @Override
    public PageUtils administrative(String typeName, int parentId, int page, int size) {
        Page<DoctorVo> doctorListVoPage = new Page<>(page, size);
        IPage<DoctorVo> all=hospitalDoctorDao.administrative(doctorListVoPage,typeName,parentId);
        PageUtils pageUtils = new PageUtils(all);
        return pageUtils;
    }

    //该科室下的医生等级信息
    @Override
    public PageUtils doctorlevel(String typeName, int parentId, int page, int size) {
        Page<DoctorVo> doctorListVoPage = new Page<>(page, size);
        IPage<DoctorVo> all=hospitalDoctorDao.doctorlevel(doctorListVoPage,typeName,parentId);
        PageUtils pageUtils = new PageUtils(all);
        return pageUtils;
    }

    @Override
    public List<DoctorVo> selecthospital(int parentId) {
        return hospitalDoctorDao.selecthospital(parentId);
    }

    @Override
    public String updateStatus(Integer doctorId, Integer status) {
        HospitalDoctorEntity hospitalDoctorEntity = baseMapper.selectById(doctorId);
        hospitalDoctorEntity.setDoctorApprovalState(status);
        int i = baseMapper.updateById(hospitalDoctorEntity);
        return "1";
    }




}